package com.example.cloud.lijiansleuth.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @author lj02
 * @desc
 * @date 2018/6/14
 */
@Service
public class HelloService {
    private final Logger logger = Logger.getLogger(getClass());

    @Autowired
    RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "hiError")
    public String hiService(String name) {

        if (name == null) {
            return restTemplate.getForObject("http://TEST-CLIENT2222222/showport?" + name, String.class);
        }
        logger.info("this is lijian-eureka-sleuth " + name);
        restTemplate.getForObject("http://TEST-ZIPKIN-CLIENT2/showport?" + name, String.class);

        logger.info("this is lijian-eureka-sleuth after " + name);
        return "ss";
    }

    public String hiError(String name) {
        return "hi," + name + ",sorry,error!";
    }

}